package com.gouqi.mall.mapper;

import com.gouqi.mall.domain.Enterprise;
import com.gouqi.mall.domain.EnterpriseProduct;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface EnterpriseProductMapper {

    @Options(useGeneratedKeys = true,keyProperty = "id")//添加完返回对象中有id值不为null，id自增长
    @Insert("INSERT INTO enterprise_product(name,founder,cellphone,telephone,product_address,brand_trade_mark,register_time,register_address,business_license,food_safety_permit,takeoff,takeoff_time,takeoff_reason,approval,company_id)" +
            "VALUES(#{name},#{founder},#{cellphone},#{telephone},#{productAddress},#{brandTradeMark},#{registerTime},#{registerAddress},#{businessLicense},#{foodSafetyPermit},#{takeoff},#{takeoffTime},#{takeoffReason},#{approval},#{company.id})")
    Integer addProduction(EnterpriseProduct product);

    @Update("update enterprise_product  " +
            "set name=#{name}," +
            "founder=#{founder}," +
            "cellphone=#{cellphone}," +
            "telephone=#{telephone}," +
            "product_address=#{productAddress}," +
            "brand_trade_mark=#{brandTradeMark}," +
            "register_time=#{registerTime}," +
            "register_address=#{registerAddress}," +
            "business_license=#{businessLicense}," +
            "food_safety_permit=#{foodSafetyPermit}," +
            "takeoff=#{takeoff}," +
            "takeoff_time=#{takeoffTime}," +
            "takeoff_reason=#{takeoffReason}," +
            "approval=#{approval}," +
            "company_id=#{company.id}  " +
            " where id=#{id}")
    Integer updateProduction(EnterpriseProduct product);

    @Delete("delete from enterprise_product where id=#{id}")
    Integer deleteProduction(Integer id);

    @Select("select * from enterprise_product where name like '%${name}%'")
    @Results(id="queryProduction",value={
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "name", property = "name"),
            @Result(column = "cellphone", property = "cellphone"),
            @Result(column = "telephone", property = "telephone"),
            @Result(column = "product_address", property = "productAddress"),
            @Result(column = "brand_trade_mark", property = "brandTradeMark"),
            @Result(column = "register_time", property = "registerTime"),
            @Result(column = "register_address", property = "registerAddress"),
            @Result(column = "business_license", property = "businessLicense"),
            @Result(column = "food_safety_permit", property = "foodSafetyPermit"),
            @Result(column = "takeoff", property = "takeoff"),
            @Result(column = "takeoff_time", property = "takeoffTime"),
            @Result(column = "takeoff_reason", property = "takeoffReason"),
            @Result(column = "approval", property = "approval"),
            @Result(column = "company_id",property="company",one = @One(select = "com.gouqi.mall.mapper.EnterpriseMapper.selectEnterpriseById"))
    })
    List<EnterpriseProduct> queryProduction(@Param(value = "name")String name);

    @Select("select * from enterprise_product where company_id=#{companyId}")
    List<EnterpriseProduct> findProductsByEnterpriseId(@Param(value = "companyId")String companyId);
}
